package com.example.mapper.pc;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.entity.mysql.Resourcegroup;
import com.example.entity.vo.pc.*;
import com.example.entity.yifei.Moctb;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

public interface LingLiaoMapper {

    /**
     * 勾选  【不根据排产计划领料】
     * @param dto
     * @return
     */
    List<LingLiaoListVo> listCheckBox1(LingLiaoListDto dto);

    /**
     * 不勾选  【不根据排产计划领料】
     * @param dto
     * @return
     */
    List<LingLiaoListVo> listUnCheckBox1(LingLiaoListDto dto);

    List<OtherProductSelectVo> otherProductSelect(OtherProductSelectDto dto);

    List<OtherProductSelectVo> afterClickCheckBoxWith2(AfterClickCheckBoxDto dto);

    List<LlListVo> llList(LlListDto dto);

    @Select("SELECT ISNULL(KHGJ,'') FROM MOCTA LEFT JOIN COPTC ON TA026=TC001 AND TA027=TC002 LEFT JOIN V_KHDQ ON TC004=KHBH " +
            "WHERE TA001= #{ta001} AND TA002= #{ta002}")
    String moctcUdf04(String ta001, String ta002);

    @Select("SELECT DISTINCT TB009 FROM MOCTB LEFT JOIN INVMB ON MB001=TB003 WHERE TB001=#{type} AND TB002=#{id} AND TB011='1' AND MB042 = '1'")
    List<String> getCkListByTypeId(@Param("type")String type, @Param("id")String id);

    @Select("SELECT MOCTB.* FROM MOCTB LEFT JOIN INVMB ON MB001=TB003 WHERE TB001=#{type} AND TB002=#{id} AND TB009=#{ckId} AND TB011='1' AND MB042 = '1'")
    List<Moctb> llMoctbListByTb009(String type, String id, String ckId);

    @Select("SELECT ISNULL(TE005,0) FROM V_DL WHERE TE004=#{tb003} AND TE008=#{tb009}")
    Double uncheckNumsByMocte(@Param("tb003") String tb003, @Param("tb009") String tb009);

    @Select("SELECT ISNULL(MC007,0) FROM INVMC WHERE MC001=#{tb003} AND MC002=#{tb009}")
    Double stockNum(@Param("tb003") String tb003, @Param("tb009") String tb009);

    @Update("UPDATE MOCTA SET TA016=TA015, TA065 = 'Y' WHERE TA001=#{type} AND TA002=#{id}")
    void updateTa016(@Param("type")String type, @Param("id")String id);

    @Update("UPDATE MOCTY SET TY018='Y' WHERE UDF05 = #{uuid}")
    void updateMoctyTy018(String uuid);

    @Select("SELECT DISTINCT TB009 FROM MOCTB LEFT JOIN INVMB ON MB001=TB003 WHERE TB001=#{type} AND TB002=#{id} AND TB011='1' AND MB042 = '1' AND (TB006=#{process} OR TB006 = '****')")
    List<String> getCkListByTypeIdProcess(@Param("type")String type,@Param("id") String id, @Param("process") String process);

    @Select("SELECT MOCTB.* FROM MOCTB LEFT JOIN INVMB ON MB001=TB003 WHERE TB001=#{type} AND TB002=#{id} AND TB009=#{ckId} AND TB011='1' AND MB042 = '1' AND (TB006=#{process} OR TB006='****')")
    List<Moctb> llMoctbListMocty(@Param("type")String type,@Param("id") String id, @Param("ckId")String ckId,@Param("process") String process);

    @Select("SELECT ISNULL(C.TE005, 0) TE005 FROM V_CLDL C WHERE #{tb001}=C.TE011 AND #{tb002}=C.TE012 AND #{tb003}=C.TE004")
    BigDecimal V_CLDL(String tb001, String tb002, String tb003);

    @Select("SELECT (ISNULL(C.TE005, 0) + ISNULL(TB005, 0)) ylsl FROM MOCTB \n" +
            "LEFT JOIN V_CLDL C ON TB001= C.TE011 AND TB002=C.TE012 AND TB003=C.TE004\n" +
            "WHERE TB001 = #{type} AND TB002 = #{id} AND TB003 = #{productId}")
    BigDecimal ylsl(String type, String id, String productId);

    List<OtherProductSelectVo> replaceItemList(@Param("yuanjian") String yuanjian, @Param("zhujian") String zhujian);

    List<String> getCkListByTypeIdList(List<AutoGenLL> list);

    List<Moctb> llMoctbListByTb009List(@Param("list") List<AutoGenLL> list, @Param("ckId") String ckId);

    List<Moctb> llMoctbListByMoctyList(@Param("list") List<AutoGenLL> list, @Param("ckId") String ckId);

    List<String> ckListMoctyList(@Param("list") List<AutoGenLL> list);

    @DS("mes")
    List<Resourcegroup> getIdNameList(@Param("list") List<String> ids);

//    List<OtherProductSelectVo> afterClickCheckBoxNo2(AfterClickCheckBoxDto dto);
}
